Skip to content

Conversation

@Sicheng-Pan
Copy link
Contributor

@Sicheng-Pan Sicheng-Pan commented Feb 10, 2026

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • Updated a few structs for QuantizedSpannIndexWriter to facilitate segment writer
    • Separated scrub and rebuild centroid logic from commit to a separate finish
    • Introduces the new QuantizedSpannSegmentWriter, under the feature flag
    • Updated the VectorSegmentWriter to use the new writer impl

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Migration plan

Are there any migrations, or any forwards/backwards compatibility changes needed in order to make sure this change deploys reliably?

Observability plan

What is the plan to instrument and monitor this change?

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs section?

Copy link
Contributor Author

Sicheng-Pan commented Feb 10, 2026

@github-actions
Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@Sicheng-Pan Sicheng-Pan force-pushed the 02-10-_enh_quantized_spann_segment branch from 8bded9c to 70b715c Compare February 10, 2026 22:26
@blacksmith-sh

This comment has been minimized.

@Sicheng-Pan Sicheng-Pan changed the title [ENH] Quantized Spann Segment [ENH] Quantized Spann Segment Writer Feb 11, 2026
@Sicheng-Pan Sicheng-Pan force-pushed the 02-10-_enh_quantized_spann_segment branch from 15768fa to e3957b5 Compare February 11, 2026 02:22
@Sicheng-Pan Sicheng-Pan marked this pull request as ready for review February 11, 2026 02:23
@propel-code-bot
Copy link
Contributor

propel-code-bot bot commented Feb 11, 2026

Feature-Gating Quantized SPANN Segment Writer Pipeline

This PR introduces a complete quantized SPANN segment writer/flush pipeline, wiring it through the segment manager, schema helpers, and feature gating so quantized segments can be produced and reopened safely. The effort separates finish from commit, updates index writer lifecycle management, and propagates CMEK/scrub parameters through blockfile operations while exposing the new module under the usearch feature flag.
It also refreshes supporting infrastructure (materialized log accessors, schema-derived SPANN configuration, blockfile prefetch helpers) and removes the now-unused QuantizedSpannIds struct, ensuring the vector segment writer can delegate to the quantized implementation end-to-end.

Key Changes

• Added rust/segment/src/quantized_spann.rs implementing QuantizedSpannSegmentWriter with blockfile orchestration, cluster/centroid persistence, and feature-flag exposure
• Enhanced QuantizedSpannIndexWriter with explicit finish and commit phases, block-size configuration, ID tracking, and reopen/persist tests
• Updated VectorSegmentWriter and related enums to construct, finish, and commit quantized writers while propagating errors
• Extended schema utilities (get_spann_config, new quantized constants) and segment helpers (filepaths_to_prefetch, quantized path enumeration)
• Expanded log/materialization interfaces so BorrowedMaterializedLogRecord can expose embeddings, and ensured blockfile errors wrap QuantizedSpannSegmentError
• Removed the obsolete QuantizedSpannIds struct from rust/index/src/spann/types.rs after inlining its responsibilities elsewhere

Possible Issues

• Quantized centroid/metadata files are not included in Segment::filepaths_to_prefetch, potentially slowing reopen operations
• Collections lacking explicit SPANN config will cause get_spann_config to fail, blocking quantized writer creation unless validated upstream
apply_materialized_log_chunk treats update-without-embedding as a no-op; ensure version/delete state remains consistent
• Feature flag mismatches (enabling quantized segments without usearch) could yield missing symbol errors at compile time

This summary was automatically generated by @propel-code-bot

@blacksmith-sh

This comment has been minimized.

Comment on lines +147 to +187
QuantizedSpannSegmentError::Config(format!(
"failed to parse record segment file path: {e}"
))
})?;
let options = BlockfileReaderOptions::new(id, prefix.to_string());
let reader = blockfile_provider.read(options).await.map_err(|e| {
QuantizedSpannSegmentError::Config(format!(
"failed to open record segment reader: {e}"
))
})?;
Some(reader)
}
None => None,
},
None => None,
};

// Order matches file_path_keys: cluster[0], embedding_metadata[1],
// quantized_centroid[2], raw_centroid[3], scalar_metadata[4].
let file_ids = QuantizedSpannIds {
embedding_metadata_id: parsed[1].1,
prefix_path: prefix_path.clone(),
quantized_centroid_id: IndexUuid(parsed[2].1),
quantized_cluster_id: parsed[0].1,
raw_centroid_id: IndexUuid(parsed[3].1),
scalar_metadata_id: parsed[4].1,
};
QuantizedSpannIndexWriter::open(
cluster_block_size,
vector_segment.collection,
spann_config,
dimensionality,
distance_function,
file_ids,
cmek,
prefix_path.clone(),
raw_embedding_reader,
blockfile_provider,
usearch_provider,
)
.await?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical

[Logic] apply_materialized_log_chunk() now hard-fails whenever the materialized log record doesn’t contain an embedding inline. In production, materialize_logs() commonly hydrates embeddings from the record segment (the log itself often omits them after compaction), so legitimate AddNew/OverwriteExisting operations will now panic with QuantizedSpannSegmentError::Data. You should accept the RecordSegmentReader that’s already being passed to VectorSegmentWriter::apply_materialized_log_chunk, hydrate the record when embeddings_ref_from_log() returns None, and only error when both sources are missing. For example:

pub async fn apply_materialized_log_chunk(
    &self,
    record_segment_reader: &RecordSegmentReader<'_>,
    materialized_chunk: &MaterializeLogsResult,
) -> Result<(), ApplyMaterializedLogError> {
    for record in materialized_chunk {
        let embedding = match record.embeddings_ref_from_log() {
            Some(v) => Cow::Borrowed(v),
            None => Cow::Owned(
                record
                    .hydrate(record_segment_reader, 1)
                    .await?
                    .embedding
                    .to_vec(),
            ),
        };
        self.index.add(record.get_offset_id(), &embedding).await?;
    }
    Ok(())
}

Without this fallback any replay that relies on the record segment (which is the default case) will immediately fail.

Context for Agents
`apply_materialized_log_chunk()` now hard-fails whenever the materialized log record doesn’t contain an embedding inline. In production, `materialize_logs()` commonly hydrates embeddings from the record segment (the log itself often omits them after compaction), so legitimate `AddNew`/`OverwriteExisting` operations will now panic with `QuantizedSpannSegmentError::Data`. You should accept the `RecordSegmentReader` that’s already being passed to `VectorSegmentWriter::apply_materialized_log_chunk`, hydrate the record when `embeddings_ref_from_log()` returns `None`, and only error when both sources are missing. For example:

```rust
pub async fn apply_materialized_log_chunk(
    &self,
    record_segment_reader: &RecordSegmentReader<'_>,
    materialized_chunk: &MaterializeLogsResult,
) -> Result<(), ApplyMaterializedLogError> {
    for record in materialized_chunk {
        let embedding = match record.embeddings_ref_from_log() {
            Some(v) => Cow::Borrowed(v),
            None => Cow::Owned(
                record
                    .hydrate(record_segment_reader, 1)
                    .await?
                    .embedding
                    .to_vec(),
            ),
        };
        self.index.add(record.get_offset_id(), &embedding).await?;
    }
    Ok(())
}
```
Without this fallback any replay that relies on the record segment (which is the default case) will immediately fail.

File: rust/segment/src/quantized_spann.rs
Line: 187

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddNew/OverwriteExisting requires embedding to be present as a system invariance

@Sicheng-Pan Sicheng-Pan force-pushed the 02-10-_enh_quantized_spann_segment branch from 22ff37f to fa35f48 Compare February 12, 2026 01:40
@Sicheng-Pan Sicheng-Pan force-pushed the 02-10-_enh_quantized_spann_segment branch from fa35f48 to b02eb80 Compare February 12, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant